file(GLOB modulePaths ./*)
foreach(module ${modulePaths})
    if (NOT IS_DIRECTORY  "${module}")
        continue()
    endif ()

    if (NOT EXISTS "${module}/CMakeLists.txt")
        continue()
    endif ()

    cmake_path(GET module STEM name)
    add_subdirectory(${module})
endforeach()

function(CreateModule _inRelativePath _inIsInterface)
    set(CreatePath "${CMAKE_CURRENT_SOURCE_DIR}/${_inRelativePath}")
    if (EXISTS  "${CreatePath}")
        return()
    endif ()

    cmake_path(GET CreatePath STEM OriginModuleName)
    string(TOUPPER ${OriginModuleName} UpperModuleName)

    #    TODO 暂未处理多级目录和现有模块目录情况
    file(MAKE_DIRECTORY "${CreatePath}")
    file(MAKE_DIRECTORY "${CreatePath}/include")

    configure_file(${CMAKE_SOURCE_DIR}/template/ModuleTemplate/include/Global.h.in
            ${CreatePath}/include/${OriginModuleName}Global.h
            @ONLY
    )
    #    接口module
    if(_inIsInterface)

        configure_file(${CMAKE_SOURCE_DIR}/template/ModuleTemplate/InterfaceCMakeLists.txt.in
                ${CreatePath}/CMakeLists.txt
                @ONLY
        )
    #   普通模块
    else()
        file(MAKE_DIRECTORY "${CreatePath}/src")

        configure_file(${CMAKE_SOURCE_DIR}/template/ModuleTemplate/CommonCMakeLists.txt.in
                ${CreatePath}/CMakeLists.txt
                @ONLY
        )
    endif()
endfunction()

CreateModule(Net false)